<?php 

function connettiDb()

{
	require_once 'config.php';
	mysql_connect($db['host'],$db['userdb'],$db['password']) 
or die('impossibile collegarsi al server');	

mysql_select_db($db['nomeDb'])
or die('impossibile collegarsi al databse');		
}
function getPage($id, $lang= 'it')
{
	connettiDb();
/*$sql_it = "select *, title_it AS title, content_it AS content from pages where id= $id and status=1";
$sql_en = "select *, title_en AS title, content_en AS content from pages where id= $id and status=1";

if ($lang=='it')
{
	$sql=$sql_it;
}
else {
	$sql=$sql_en;
}*/
	$sql = "select id, section, sub_section, status, title_$lang as title,
	 content_$lang as content from pages where id= $id and status=1";
	

	
$result = mysql_query($sql);

return $result;
}
function getAlPages($lang='it')
{
	connettiDb();
	$sql = "select id, section, sub_section, status, title_$lang as title,
	 content_$lang as content from pages where status=1
	 ORDER BY title asc";

$result = mysql_query($sql);

return $result;
}
function getAlPagesBySection($section, $lang='it')
{
	connettiDb();
	$sql = "select id, section, sub_section, status, title_$lang as title,
	 content_$lang as content from pages where status=1 and section =$section
	 ORDER BY sub_section, title";

$result = mysql_query($sql);

return $result;
}

function getAllPagesBySubSection($section, $subSection, $lang ='it')
{
	connettiDb();
	$sql = "select id, section, sub_section, status, title_$lang as title,
	 content_$lang as content from pages where status=1 and section =$section
	 AND sub_section = $subSection
	 ORDER BY sub_section, title";

$result = mysql_query($sql);

return $result;
}
function isCorrectSection($request)
{
	require_once 'config.php';
	
	return isset($sections[$request]);
}




